package com.yinp.proapp.utils;

import android.content.res.Resources;
import android.view.Gravity;
import android.widget.Toast;

import androidx.annotation.IntDef;

import com.yinp.proapp.base.App;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;


public class ToastUtil {
    public static final int LENGTH_SHORT = Toast.LENGTH_SHORT;
    public static final int LENGTH_LONG = Toast.LENGTH_LONG;
    /**
     * @hide
     */
    @IntDef(value = {
            LENGTH_SHORT,
            LENGTH_LONG
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Duration {
    }

    public static void initToast(int resId) {
        initToast(Resources.getSystem().getText(resId));
    }

    public static void initToast(CharSequence text) {
        initToast(text, LENGTH_SHORT);
    }

    public static void initToast(CharSequence text, @Duration int time) {
        Toast toast = new Toast(App.appContext);
        toast.setGravity(Gravity.BOTTOM, 0, 70);
        toast.setDuration(time);
        toast.setText(text);
        toast.show();
    }

}
